#|.| |*| |?| |.*| |.*?| |+| |{m,n}|
import re
#. 匹配任意除\n外的单个字符,指定re.DOTALL后才能匹配\n
print(re.findall('a.b','a1b a2b a b abbbb a\nb a\tb a*b'))
print(re.findall('a.b','a1b a2b a b abbbb a\nb a\tb a*b',re.DOTALL))#
print(re.findall('a.b','a1b a2b a b abbbb a\nb a\tb a*b',re.S))

#* :跟其他字符一起用,左侧字符重复0次或无穷次，性格贪婪，相当于{0,}
print(re.findall('ab*','a'))
print(re.findall('ab*','a abbb ab abbbbb abbbbbbb bbbbbb'))

# + :左侧字符出现1次或无穷次，性格贪婪,相当于{1,}
print(re.findall('ab+','a abbb ab abbbbb abbbbbbb bbbbbb'))

# ?:左侧字符出现1次或0次，性格贪婪,相当于{0,1}
print(re.findall('ab?','a abbb ab abbbbb abbbbbbb bbbbbb'))

# {n,m}:左侧字符出现n次到m次，{n},只出现n次性格贪婪
print(re.findall('ab{2,5}','a abbb ab abbbbb abbbbbbb bbbbbb abbbbbbbbbb abbbbb baaaaabbbbb'))

#练习
#找出整数跟小数
print(re.findall('\d+\.?\d*','asdfasdf123as1.13dfa12adsf1asdf3a1.0a1..1'))

#[]:匹配指定字符的一个
print(re.findall('a[0-9a-zA-Z]*b','a1b a3b asb a4b a9b a b  a12b  aa45sb a45Bb a\nb'))
print(re.findall('a[^0-9a-zA-Z]*b','a1b a3b asb a4b a9b a b  a12b  aa45sb a45Bb a\nb'))#^  取反


a='<a href="article.php?id=xxxx" target="_blank" class="xxxx_doc">26项xxx发布</a>'
print(re.findall('<a href="article.php\?id=xxxx" target="_blank" class="xxxx_doc">(.*?)</a>',a))

print(re.findall('<a .*>(.*?)</a>',a))

one='mdfsdsfffdsn123456n'
pattern=re.compile('m(.*)n')
result=pattern.findall(one)
print(result)
print(re.findall('m(.*)n',one))

pattern=re.compile('^\d+$')
one='234'
result=pattern.match(one)
print(result.group())

#范围运算 [123] [1-9]
one='789345'
pattern=re.compile('[123]')
result=pattern.findall(one)
print(result)#['3'] 或的关系
result=pattern.search(one)
print(result.group())



one='123abc'
pattern=re.compile('\d+')
#match： 从头开始匹配，只匹配一次
result=pattern.match(one)
print(result.group())
#search： 从任意位置开始匹配，只匹配一次
result=pattern.search(one)
print(result.group())
#sub
result=pattern.sub('#',one)
print(result)
#split 拆分
one='123 abc'
pattern=re.compile(' ')
result=pattern.split(one)
print(result)
